package lrz.shiftplanner.components;
import java.awt.Font;
import java.util.HashMap;
import java.util.LinkedList;

import javax.swing.JComponent;

public class AdaptFontFactory {

	//private static float scale = 1.0f;

	private static Font f1 = new Font("Arial", Font.BOLD, 16);
	private static Font f2 = new Font("Arial", Font.BOLD, 16);
	private static Font f3 = new Font("Arial", Font.BOLD, 14);
	private static Font f4 = new Font("Arial", Font.BOLD, 18);
	private static Font f5 = new Font("Arial", Font.BOLD, 15);
	
	private static LinkedList<JComponent> components = new LinkedList<JComponent>();
	
	private static HashMap<JComponent, Integer> assignements = new HashMap<JComponent, Integer>();

	public static final int SMALL = 0;
	public static final int MEDIUM = 1;
	public static final int LARGE = 2;
	public static final int SELECTOR = 3;
	public static final int SELECTORSMALL = 4;

	public static void setScale(float scale) {
		//AdaptFontFactory.scale = scale;

		f1 = new Font("Arial", Font.BOLD, (int) (16 * scale));
		f2 = new Font("Arial", Font.BOLD, (int) (16 * scale));
		f3 = new Font("Arial", Font.BOLD, (int) (15 * scale));
		f4 = new Font("Arial", Font.BOLD, (int) (18 * scale));
		f5 = new Font("Arial", Font.BOLD, (int) (13 * scale));
		
		for (JComponent component : components) {
			component.setFont(getFont(assignements.get(component)));
		}
	}

	
	private static Font getFont(int FontID) {
		switch (FontID) {
		case SMALL:
			return f3;
		case MEDIUM:
			return f2;
		case LARGE:
			return f1;
		case SELECTOR:
			return f4;
		case SELECTORSMALL:
			return f5;
		default:
			return f1;
		}
	}
	
	
	public static Font registerFont(JComponent component, int FontID) {
		if (!assignements.containsKey(component))
			components.add(component);
		assignements.put(component, new Integer(FontID));
		component.setFont(getFont(assignements.get(component)));
		return getFont(FontID);
	}

	private AdaptFontFactory() {

	}
}
